package com.motus.pm.serviceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.motus.pm.dao.DeptDao;
import com.motus.pm.dao.DeptTaskDao;
import com.motus.pm.dao.EmpInfoDao;
import com.motus.pm.dao.MeetingEmpDao;
import com.motus.pm.dao.MeetingInfoDao;
import com.motus.pm.dao.MeetingTaskDao;
import com.motus.pm.dao.PhaseInfoDao;
import com.motus.pm.dao.ProjectInfoDao;
import com.motus.pm.dao.ProjectPhaseDao;
import com.motus.pm.dao.ProjectTaskDao;
import com.motus.pm.service.DeptService;
import com.motus.pm.vo.MotusDept;
import com.motus.pm.vo.MotusEmpInfo;
import com.motus.pm.vo.PmDeptTask;
import com.motus.pm.vo.PmMeetingEmp;
import com.motus.pm.vo.PmMeetingInfo;
import com.motus.pm.vo.PmMeetingTask;
import com.motus.pm.vo.PmPhaseInfo;
import com.motus.pm.vo.PmProjectInfo;
import com.motus.pm.vo.PmProjectPhase;
import com.motus.pm.vo.PmProjectPhaseId;
import com.motus.pm.vo.PmProjectTask;

@Service
@Transactional
public class DeptServiceImpl implements DeptService {
	
	@Autowired
	@Qualifier("projectPhaseDaoImpl")
	private ProjectPhaseDao projectPhaseDao;
	
	@Autowired
	@Qualifier("projectInfoDaoImpl")
	private ProjectInfoDao projectInfoDao;
	
	@Autowired
	@Qualifier("phaseInfoDaoImpl")
	private PhaseInfoDao phaseInfoDao;
	
	@Autowired
	@Qualifier("empInfoDaoImpl")
	private EmpInfoDao empInfoDao;
	
	@Autowired
	@Qualifier("projectTaskDaoImpl")
	private ProjectTaskDao projectTaskDao;
	
	@Autowired
	@Qualifier("deptTaskDaoImpl")
	private DeptTaskDao deptTaskDao;
	
	@Autowired
	@Qualifier("meetingTaskDaoImpl")
	private MeetingTaskDao meetingTaskDao;
	
	@Autowired
	@Qualifier("meetingInfoDaoImpl")
	private MeetingInfoDao meetingInfoDao;
	
	@Autowired
	@Qualifier("meetingEmpDaoImpl")
	private MeetingEmpDao meetingEmpDao;
	
	@Autowired
	@Qualifier("deptDaoImpl")
	private DeptDao deptDao;

	@Override
	public List<PmProjectPhase> getProjectPhasesByDeptId(int deptId) {
		return projectPhaseDao.getProjectPhasesByDeptId(deptId);
	}

	@Override
	public List<PmProjectInfo> getProjectInfosByDeptId(int deptId) {
		return projectInfoDao.getProjectInfosByDeptId(deptId);
	}

	@Override
	public List<PmPhaseInfo> getPhaseInfosByDeptIdAndPid(int deptId, String pid) {
		return phaseInfoDao.getPhaseInfosByDeptIdAndPid(deptId, pid);
	}

	@Override
	public PmProjectPhase getProjectPhaseById(PmProjectPhaseId pmProjectPhaseId) {
		return projectPhaseDao.getById(pmProjectPhaseId);
	}

	@Override
	public PmProjectInfo getProjectInfoById(String pid) {
		return projectInfoDao.getById(pid);
	}

	@Override
	public PmPhaseInfo getPhaseInfoById(String phaseId) {
		return phaseInfoDao.getById(phaseId);
	}

	@Override
	public List<MotusEmpInfo> getEmpInfosByDeptId(int deptId) {
		return empInfoDao.getEmpInfosByDeptId(deptId);
	}

	@Override
	public MotusEmpInfo getEmpInfosById(int id) {
		return empInfoDao.getById(id);
	}

	@Override
	public void newProjectTask(PmProjectTask pmProjectTask) {
		projectTaskDao.save(pmProjectTask);
		PmProjectPhaseId pmProjectPhaseId=new PmProjectPhaseId((pmProjectTask).getPmProjectInfo(),(pmProjectTask).getPmPhaseInfo());
		PmProjectPhase pmProjectPhase=projectPhaseDao.getById(pmProjectPhaseId);
		pmProjectPhase.setPhaseState(0);
		projectPhaseDao.update(pmProjectPhase);
	}

	@Override
	public List<PmProjectTask> getProjectTasksByDeptIdAndTaskState(
			int deptId, int taskState) {
		return projectTaskDao.getProjectTasksByDeptIdAndTaskState(deptId, taskState);
	}

	@Override
	public PmProjectTask getProjectTaskById(int taskId) {
		return projectTaskDao.taskById(taskId);
	}

	@Override
	public void updateProjectTask(PmProjectTask projectTask) {
		// TODO Auto-generated method stub
		projectTaskDao.update(projectTask);
	}
	
	@Override
	public List<PmDeptTask> getDeptTasksByDeptId(int deptId) {
		return deptTaskDao.getDeptTasksByDeptId(deptId);
	}

	@Override
	public List<PmDeptTask> getDeptTasksByDeptIdAndTaskState(int deptId,
			int taskState) {
		return deptTaskDao.getDeptTasksByDeptIdAndTaskState(deptId, taskState);
	}

	@Override
	public PmDeptTask getDeptTaskById(int deptTaskId) {
		return deptTaskDao.getById(deptTaskId);
	}

	@Override
	public void newMeetingTask(PmMeetingTask meetingTask) {
		meetingTaskDao.save(meetingTask);
	}

	@Override
	public List<PmMeetingTask> getMeetingTasksByDeptIdAndTaskState(int deptId,
			int taskState) {
		return meetingTaskDao.getMeetingTasksByDeptIdAndTaskState(deptId, taskState);
	}

	@Override
	public List<PmMeetingInfo> getMeetingInfosByDeptId(int deptId) {
		return meetingInfoDao.getMeetingInfosByDeptId(deptId);
	}

//	@Override
//	public PmMeetingInfo getMeetingInfoById(int mid) {
//		return meetingInfoDao.getById(mid);
//	}

	@Override
	public List<PmMeetingEmp> getMeetingEmpsByMid(int mid) {
		return meetingEmpDao.getMeetingEmpsByMid(mid);
	}

	@Override
	public MotusDept getMotusDeptById(int deptId) {
		return deptDao.getById(deptId);
	}

	@Override
	public void newDeptMeeting(PmMeetingInfo pmMeetingInfo) {
		meetingInfoDao.save(pmMeetingInfo);
	}

}
